Combined sampler and compute binding.
This commit is contained in:
parent
99af670622
commit
069de61bdb
86
src/bgfx_p.h
86
src/bgfx_p.h
@ -1031,10 +1031,31 @@ namespace bgfx
|
|||||||
UniformHashMap m_uniforms;
|
UniformHashMap m_uniforms;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Sampler
|
struct Binding
|
||||||
|
{
|
||||||
|
enum Enum
|
||||||
|
{
|
||||||
|
Image,
|
||||||
|
IndexBuffer,
|
||||||
|
VertexBuffer,
|
||||||
|
Texture,
|
||||||
|
|
||||||
|
Count
|
||||||
|
};
|
||||||
|
|
||||||
|
uint16_t m_idx;
|
||||||
|
uint8_t m_type;
|
||||||
|
|
||||||
|
union
|
||||||
{
|
{
|
||||||
uint32_t m_flags;
|
uint32_t m_flags;
|
||||||
uint16_t m_idx;
|
struct
|
||||||
|
{
|
||||||
|
uint8_t m_format;
|
||||||
|
uint8_t m_access;
|
||||||
|
uint8_t m_mip;
|
||||||
|
} m_compute;
|
||||||
|
} m_un;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RenderDraw
|
struct RenderDraw
|
||||||
@ -1064,8 +1085,9 @@ namespace bgfx
|
|||||||
|
|
||||||
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++ii)
|
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++ii)
|
||||||
{
|
{
|
||||||
m_sampler[ii].m_idx = invalidHandle;
|
m_bind[ii].m_idx = invalidHandle;
|
||||||
m_sampler[ii].m_flags = 0;
|
m_bind[ii].m_type = uint8_t(Binding::Texture);
|
||||||
|
m_bind[ii].m_un.m_flags = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1090,25 +1112,7 @@ namespace bgfx
|
|||||||
VertexDeclHandle m_vertexDecl;
|
VertexDeclHandle m_vertexDecl;
|
||||||
IndexBufferHandle m_indexBuffer;
|
IndexBufferHandle m_indexBuffer;
|
||||||
VertexBufferHandle m_instanceDataBuffer;
|
VertexBufferHandle m_instanceDataBuffer;
|
||||||
Sampler m_sampler[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
|
Binding m_bind[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
|
||||||
};
|
|
||||||
|
|
||||||
struct ComputeBinding
|
|
||||||
{
|
|
||||||
enum Enum
|
|
||||||
{
|
|
||||||
Image,
|
|
||||||
VertexBuffer,
|
|
||||||
IndexBuffer,
|
|
||||||
|
|
||||||
Count
|
|
||||||
};
|
|
||||||
|
|
||||||
uint16_t m_idx;
|
|
||||||
uint8_t m_format;
|
|
||||||
uint8_t m_access;
|
|
||||||
uint8_t m_mip;
|
|
||||||
uint8_t m_type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RenderCompute
|
struct RenderCompute
|
||||||
@ -1140,7 +1144,7 @@ namespace bgfx
|
|||||||
uint16_t m_num;
|
uint16_t m_num;
|
||||||
uint8_t m_submitFlags;
|
uint8_t m_submitFlags;
|
||||||
|
|
||||||
ComputeBinding m_bind[BGFX_MAX_COMPUTE_BINDINGS];
|
Binding m_bind[BGFX_MAX_COMPUTE_BINDINGS];
|
||||||
};
|
};
|
||||||
|
|
||||||
union RenderItem
|
union RenderItem
|
||||||
@ -1382,9 +1386,9 @@ namespace bgfx
|
|||||||
|
|
||||||
void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags)
|
void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags)
|
||||||
{
|
{
|
||||||
Sampler& sampler = m_draw.m_sampler[_stage];
|
Binding& sampler = m_draw.m_bind[_stage];
|
||||||
sampler.m_idx = _handle.idx;
|
sampler.m_idx = _handle.idx;
|
||||||
sampler.m_flags = (_flags&BGFX_SAMPLER_DEFAULT_FLAGS) ? BGFX_SAMPLER_DEFAULT_FLAGS : _flags;
|
sampler.m_un.m_flags = (_flags&BGFX_SAMPLER_DEFAULT_FLAGS) ? BGFX_SAMPLER_DEFAULT_FLAGS : _flags;
|
||||||
|
|
||||||
if (isValid(_sampler)
|
if (isValid(_sampler)
|
||||||
&& (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) ) )
|
&& (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) ) )
|
||||||
@ -1396,32 +1400,32 @@ namespace bgfx
|
|||||||
|
|
||||||
void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access)
|
void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access)
|
||||||
{
|
{
|
||||||
ComputeBinding& bind = m_compute.m_bind[_stage];
|
Binding& bind = m_compute.m_bind[_stage];
|
||||||
bind.m_idx = _handle.idx;
|
bind.m_idx = _handle.idx;
|
||||||
bind.m_format = 0;
|
bind.m_type = uint8_t(Binding::IndexBuffer);
|
||||||
bind.m_access = uint8_t(_access);
|
bind.m_un.m_compute.m_format = 0;
|
||||||
bind.m_mip = 0;
|
bind.m_un.m_compute.m_access = uint8_t(_access);
|
||||||
bind.m_type = uint8_t(ComputeBinding::IndexBuffer);
|
bind.m_un.m_compute.m_mip = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access)
|
void setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access)
|
||||||
{
|
{
|
||||||
ComputeBinding& bind = m_compute.m_bind[_stage];
|
Binding& bind = m_compute.m_bind[_stage];
|
||||||
bind.m_idx = _handle.idx;
|
bind.m_idx = _handle.idx;
|
||||||
bind.m_format = 0;
|
bind.m_type = uint8_t(Binding::VertexBuffer);
|
||||||
bind.m_access = uint8_t(_access);
|
bind.m_un.m_compute.m_format = 0;
|
||||||
bind.m_mip = 0;
|
bind.m_un.m_compute.m_access = uint8_t(_access);
|
||||||
bind.m_type = uint8_t(ComputeBinding::VertexBuffer);
|
bind.m_un.m_compute.m_mip = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, TextureFormat::Enum _format, Access::Enum _access)
|
void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, TextureFormat::Enum _format, Access::Enum _access)
|
||||||
{
|
{
|
||||||
ComputeBinding& bind = m_compute.m_bind[_stage];
|
Binding& bind = m_compute.m_bind[_stage];
|
||||||
bind.m_idx = _handle.idx;
|
bind.m_idx = _handle.idx;
|
||||||
bind.m_format = uint8_t(_format);
|
bind.m_type = uint8_t(Binding::Image);
|
||||||
bind.m_access = uint8_t(_access);
|
bind.m_un.m_compute.m_format = uint8_t(_format);
|
||||||
bind.m_mip = _mip;
|
bind.m_un.m_compute.m_access = uint8_t(_access);
|
||||||
bind.m_type = uint8_t(ComputeBinding::Image);
|
bind.m_un.m_compute.m_mip = _mip;
|
||||||
|
|
||||||
if (isValid(_sampler)
|
if (isValid(_sampler)
|
||||||
&& (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) ) )
|
&& (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) ) )
|
||||||
|
@ -3200,15 +3200,15 @@ namespace bgfx
|
|||||||
|
|
||||||
for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii)
|
for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii)
|
||||||
{
|
{
|
||||||
const ComputeBinding& bind = compute.m_bind[ii];
|
const Binding& bind = compute.m_bind[ii];
|
||||||
if (invalidHandle != bind.m_idx)
|
if (invalidHandle != bind.m_idx)
|
||||||
{
|
{
|
||||||
switch (bind.m_type)
|
switch (bind.m_type)
|
||||||
{
|
{
|
||||||
case ComputeBinding::Image:
|
case Binding::Image:
|
||||||
{
|
{
|
||||||
const TextureD3D11& texture = m_textures[bind.m_idx];
|
const TextureD3D11& texture = m_textures[bind.m_idx];
|
||||||
if (Access::Read != bind.m_access)
|
if (Access::Read != bind.m_un.m_compute.m_access)
|
||||||
{
|
{
|
||||||
uav[ii] = texture.m_uav;
|
uav[ii] = texture.m_uav;
|
||||||
}
|
}
|
||||||
@ -3220,14 +3220,14 @@ namespace bgfx
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ComputeBinding::IndexBuffer:
|
case Binding::IndexBuffer:
|
||||||
case ComputeBinding::VertexBuffer:
|
case Binding::VertexBuffer:
|
||||||
{
|
{
|
||||||
const BufferD3D11& buffer = ComputeBinding::IndexBuffer == bind.m_type
|
const BufferD3D11& buffer = Binding::IndexBuffer == bind.m_type
|
||||||
? m_indexBuffers[bind.m_idx]
|
? m_indexBuffers[bind.m_idx]
|
||||||
: m_vertexBuffers[bind.m_idx]
|
: m_vertexBuffers[bind.m_idx]
|
||||||
;
|
;
|
||||||
if (Access::Read != bind.m_access)
|
if (Access::Read != bind.m_un.m_compute.m_access)
|
||||||
{
|
{
|
||||||
uav[ii] = buffer.m_uav;
|
uav[ii] = buffer.m_uav;
|
||||||
}
|
}
|
||||||
@ -3443,16 +3443,16 @@ namespace bgfx
|
|||||||
uint32_t changes = 0;
|
uint32_t changes = 0;
|
||||||
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
|
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
|
||||||
{
|
{
|
||||||
const Sampler& sampler = draw.m_sampler[stage];
|
const Binding& sampler = draw.m_bind[stage];
|
||||||
Sampler& current = currentState.m_sampler[stage];
|
Binding& current = currentState.m_bind[stage];
|
||||||
if (current.m_idx != sampler.m_idx
|
if (current.m_idx != sampler.m_idx
|
||||||
|| current.m_flags != sampler.m_flags
|
|| current.m_un.m_flags != sampler.m_un.m_flags
|
||||||
|| programChanged)
|
|| programChanged)
|
||||||
{
|
{
|
||||||
if (invalidHandle != sampler.m_idx)
|
if (invalidHandle != sampler.m_idx)
|
||||||
{
|
{
|
||||||
TextureD3D11& texture = m_textures[sampler.m_idx];
|
TextureD3D11& texture = m_textures[sampler.m_idx];
|
||||||
texture.commit(stage, sampler.m_flags);
|
texture.commit(stage, sampler.m_un.m_flags);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -3168,15 +3168,15 @@ namespace bgfx
|
|||||||
{
|
{
|
||||||
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
|
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
|
||||||
{
|
{
|
||||||
const Sampler& sampler = draw.m_sampler[stage];
|
const Binding& sampler = draw.m_bind[stage];
|
||||||
Sampler& current = currentState.m_sampler[stage];
|
Binding& current = currentState.m_bind[stage];
|
||||||
if (current.m_idx != sampler.m_idx
|
if (current.m_idx != sampler.m_idx
|
||||||
|| current.m_flags != sampler.m_flags
|
|| current.m_un.m_flags != sampler.m_un.m_flags
|
||||||
|| programChanged)
|
|| programChanged)
|
||||||
{
|
{
|
||||||
if (invalidHandle != sampler.m_idx)
|
if (invalidHandle != sampler.m_idx)
|
||||||
{
|
{
|
||||||
m_textures[sampler.m_idx].commit(stage, sampler.m_flags);
|
m_textures[sampler.m_idx].commit(stage, sampler.m_un.m_flags);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -4373,20 +4373,27 @@ namespace bgfx
|
|||||||
GLbitfield barrier = 0;
|
GLbitfield barrier = 0;
|
||||||
for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii)
|
for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii)
|
||||||
{
|
{
|
||||||
const ComputeBinding& bind = compute.m_bind[ii];
|
const Binding& bind = compute.m_bind[ii];
|
||||||
if (invalidHandle != bind.m_idx)
|
if (invalidHandle != bind.m_idx)
|
||||||
{
|
{
|
||||||
switch (bind.m_type)
|
switch (bind.m_type)
|
||||||
{
|
{
|
||||||
case ComputeBinding::Image:
|
case Binding::Image:
|
||||||
{
|
{
|
||||||
const TextureGL& texture = m_textures[bind.m_idx];
|
const TextureGL& texture = m_textures[bind.m_idx];
|
||||||
GL_CHECK(glBindImageTexture(ii, texture.m_id, bind.m_mip, GL_FALSE, 0, s_access[bind.m_access], s_imageFormat[bind.m_format]) );
|
GL_CHECK(glBindImageTexture(ii
|
||||||
|
, texture.m_id
|
||||||
|
, bind.m_un.m_compute.m_mip
|
||||||
|
, GL_FALSE
|
||||||
|
, 0
|
||||||
|
, s_access[bind.m_un.m_compute.m_access]
|
||||||
|
, s_imageFormat[bind.m_un.m_compute.m_format])
|
||||||
|
);
|
||||||
barrier |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT;
|
barrier |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ComputeBinding::IndexBuffer:
|
case Binding::IndexBuffer:
|
||||||
{
|
{
|
||||||
const IndexBufferGL& buffer = m_indexBuffers[bind.m_idx];
|
const IndexBufferGL& buffer = m_indexBuffers[bind.m_idx];
|
||||||
GL_CHECK(glBindBufferBase(GL_SHADER_STORAGE_BUFFER, ii, buffer.m_id));
|
GL_CHECK(glBindBufferBase(GL_SHADER_STORAGE_BUFFER, ii, buffer.m_id));
|
||||||
@ -4394,7 +4401,7 @@ namespace bgfx
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ComputeBinding::VertexBuffer:
|
case Binding::VertexBuffer:
|
||||||
{
|
{
|
||||||
const VertexBufferGL& buffer = m_vertexBuffers[bind.m_idx];
|
const VertexBufferGL& buffer = m_vertexBuffers[bind.m_idx];
|
||||||
GL_CHECK(glBindBufferBase(GL_SHADER_STORAGE_BUFFER, ii, buffer.m_id));
|
GL_CHECK(glBindBufferBase(GL_SHADER_STORAGE_BUFFER, ii, buffer.m_id));
|
||||||
@ -4747,16 +4754,16 @@ namespace bgfx
|
|||||||
{
|
{
|
||||||
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
|
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
|
||||||
{
|
{
|
||||||
const Sampler& sampler = draw.m_sampler[stage];
|
const Binding& sampler = draw.m_bind[stage];
|
||||||
Sampler& current = currentState.m_sampler[stage];
|
Binding& current = currentState.m_bind[stage];
|
||||||
if (current.m_idx != sampler.m_idx
|
if (current.m_idx != sampler.m_idx
|
||||||
|| current.m_flags != sampler.m_flags
|
|| current.m_un.m_flags != sampler.m_un.m_flags
|
||||||
|| programChanged)
|
|| programChanged)
|
||||||
{
|
{
|
||||||
if (invalidHandle != sampler.m_idx)
|
if (invalidHandle != sampler.m_idx)
|
||||||
{
|
{
|
||||||
TextureGL& texture = m_textures[sampler.m_idx];
|
TextureGL& texture = m_textures[sampler.m_idx];
|
||||||
texture.commit(stage, sampler.m_flags);
|
texture.commit(stage, sampler.m_un.m_flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user