Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel #3219

Merged
merged 2 commits into from
Sep 8, 2024
Merged

Devel #3219

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions OgreMain/include/OgreRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1201,13 +1201,17 @@ namespace Ogre
void setFFPLightParams(uint32 index, bool enabled);
bool flipFrontFace() const;
static CompareFunction reverseCompareFunction(CompareFunction func);

const HardwareBufferPtr& updateDefaultUniformBuffer(GpuProgramType type, const ConstantList& params);
private:
StencilState mStencilState;

/// a global vertex buffer for global instancing
HardwareVertexBufferSharedPtr mGlobalInstanceVertexBuffer;
/// a vertex declaration for the global vertex buffer for the global instancing
VertexDeclaration* mGlobalInstanceVertexDeclaration;
/// buffers for default uniform blocks
HardwareBufferPtr mUniformBuffer[GPT_COUNT];
/// the number of global instances (this number will be multiply by the render op instance number)
uint32 mGlobalNumberOfInstances;
};
Expand Down
12 changes: 12 additions & 0 deletions OgreMain/src/OgreRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ namespace Ogre {
mFixedFunctionParams->setAutoConstant(light_offset + 5, GpuProgramParameters::ACT_SPOTLIGHT_PARAMS, index);
}

const HardwareBufferPtr& RenderSystem::updateDefaultUniformBuffer(GpuProgramType gptype, const ConstantList& params)
{
auto& ubo = mUniformBuffer[gptype];
if (!ubo || ubo->getSizeInBytes() < params.size())
{
ubo = HardwareBufferManager::getSingleton().createUniformBuffer(params.size());
}

ubo->writeData(0, params.size(), params.data(), true);

return ubo;
}
//-----------------------------------------------------------------------
RenderSystem::~RenderSystem()
{
Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/Direct3D11/include/OgreD3D11HLSLProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ namespace Ogre {
};

typedef std::vector<D3D11_SIGNATURE_PARAMETER_DESC> D3d11ShaderParameters;
typedef std::map<String, int> BufferInfoMap;
protected:

static CmdTarget msCmdTarget;
Expand Down Expand Up @@ -106,7 +107,6 @@ namespace Ogre {
HardwareBufferPtr mDefaultBuffer; // for $Globals OR $Params

// Make sure that objects have index and name, or some search will fail
typedef std::map<String, int> BufferInfoMap;
BufferInfoMap mBufferInfoMap;

// Map to store interface slot position.
Expand Down Expand Up @@ -182,7 +182,7 @@ namespace Ogre {
ID3D11ComputeShader* getComputeShader(void) const;
const MicroCode & getMicroCode(void) const;

std::vector<ID3D11Buffer*> getConstantBuffers(const GpuProgramParametersPtr& params);
const BufferInfoMap& getBufferInfoMap() const { return mBufferInfoMap; }

// Get slot for a specific interface
unsigned int getSubroutineSlot(const String& subroutineSlotName) const;
Expand Down
13 changes: 1 addition & 12 deletions RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ namespace Ogre

bool mReadBackAsTexture;

D3D11HLSLProgram* mBoundVertexProgram;
D3D11HLSLProgram* mBoundFragmentProgram;
D3D11HLSLProgram* mBoundGeometryProgram;
D3D11HLSLProgram* mBoundTessellationHullProgram;
D3D11HLSLProgram* mBoundTessellationDomainProgram;
D3D11HLSLProgram* mBoundComputeProgram;
std::array<D3D11HLSLProgram*, GPT_COUNT> mBoundProgram;

ComPtr<ID3D11ShaderResourceView> mDSTResView;
ComPtr<ID3D11BlendState> mBoundBlendState;
Expand Down Expand Up @@ -259,12 +254,6 @@ namespace Ogre
void setStencilState(const StencilState& state) override;

// Low-level overridden members, mainly for internal use
D3D11HLSLProgram* _getBoundVertexProgram() const;
D3D11HLSLProgram* _getBoundFragmentProgram() const;
D3D11HLSLProgram* _getBoundGeometryProgram() const;
D3D11HLSLProgram* _getBoundTessellationHullProgram() const;
D3D11HLSLProgram* _getBoundTessellationDomainProgram() const;
D3D11HLSLProgram* _getBoundComputeProgram() const;
void _setTexture(size_t unit, bool enabled, const TexturePtr &texPtr);
void _setSampler(size_t unit, Sampler& sampler);
void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
Expand Down
38 changes: 4 additions & 34 deletions RenderSystems/Direct3D11/src/OgreD3D11HLSLProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,8 @@ namespace Ogre {
{
getConstantDefinitions();

bool hasDefaultBuffer = false;

for(UINT b = 0; b < mConstantBufferNr; b++)
{
switch (mD3d11ShaderBufferDescs[b].Type)
Expand All @@ -819,12 +821,13 @@ namespace Ogre {
String cb_name = mD3d11ShaderBufferDescs[b].Name;
if(cb_name == "$Globals" || cb_name == "$Params" || cb_name == "OgreUniforms")
{
if(mDefaultBuffer)
if(hasDefaultBuffer)
LogManager::getSingleton().logError(mName+" - default cbuffer already exists. Ignoring "+cb_name);
else
{
mDefaultBuffer = HardwareBufferManager::getSingleton().createUniformBuffer(mD3d11ShaderBufferDescs[b].Size);
}
hasDefaultBuffer = true;
}
else
{
Expand Down Expand Up @@ -1514,39 +1517,6 @@ namespace Ogre {
return it->second;
}
//-----------------------------------------------------------------------------
std::vector<ID3D11Buffer*> D3D11HLSLProgram::getConstantBuffers(const GpuProgramParametersPtr& params)
{
std::vector<ID3D11Buffer*> buffers;
if(mDefaultBuffer)
{
OgreAssert(mDefaultBuffer->getSizeInBytes() == params->getConstantList().size(), "unexpected buffer size");
mDefaultBuffer->writeData(0, mDefaultBuffer->getSizeInBytes(), params->getConstantList().data(), true);

buffers.push_back(static_cast<D3D11HardwareBuffer*>(mDefaultBuffer.get())->getD3DBuffer());
}
else
{
buffers.push_back(NULL);
}

for (const auto& usage : params->getSharedParameters())
{
if(const auto& buf = usage.getSharedParams()->_getHardwareBuffer())
{
// hardware baked cbuffer
auto it = mBufferInfoMap.find(usage.getName());
if(it == mBufferInfoMap.end())
continue; // TODO: error?

size_t slot = it->second;
buffers.resize(std::max(slot + 1, buffers.size()));
buffers[slot] = static_cast<D3D11HardwareBuffer*>(buf.get())->getD3DBuffer();
}
}

return buffers;
}
//-----------------------------------------------------------------------------
ID3D11VertexShader* D3D11HLSLProgram::getVertexShader(void) const
{
assert(mType == GPT_VERTEX_PROGRAM);
Expand Down
Loading