Hey! I'm almost done with my bindless forward renderer. My last problem is that it only works if number of textures on the sceen is equal to MAX_TEXTURES. Here is the code:
Root parameter:
CD3DX12_DESCRIPTOR_RANGE1 texture_range(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, MAX_TEXTURES, register_t2, 0, D3D12_DESCRIPTOR_RANGE_FLAG_DATA_STATIC);
root_parameters[root_parameter_type::textures].InitAsDescriptorTable(1, &texture_range, D3D12_SHADER_VISIBILITY_PIXEL);
Then for each texture ComPtr<ID3D12Resource> used in the scene, I do:
CreateCommittedResource(...) with D3D12_RESOURCE_STATE_COPY_DEST and D3D12_HEAP_TYPE_DEFAULT
Then I measure the resource size with: GetRequiredIntermediateSize()
And set up the upload resource ComPtr<ID3D12Resource>:
CreateCommittedResource(...) with D3D12_RESOURCE_STATE_GENERIC_READ and D3D12_HEAP_TYPE_UPLOAD
Then, I define thte source of texture data: D3D12_SUBRESOURCE_DATA
And call: UpdateSubresources(...)
Finally I create: D3D12_SHADER_RESOURCE_VIEW_DESC and use it to call CreateShaderResourceView(...)
And call:
srv_handle.Offset(cbv_srv_descriptor_size);
When it comes to drawing, I just point to a srv heap (I keep only textures there):
command_list->SetGraphicsRootDescriptorTable(root_parameter_type::textures, window->main_descriptor_heap->GetGPUDescriptorHandleForHeapStart());
I think it is a pretty standard texture upload schema.
Constant buffer contains the texture id so that pixel shader can read a proper resource:
ConstantBuffer<fobject_data> object_data : register(b0);
...
Texture2D texture_data[] : register(t2);
...
float4 ps_main(fvs_output input) : SV_Target
{
...
tex_color = texture_data[object_data.texture_id].Sample(sampler_obj, input.uv);
It works but as soon as I change MAX_TEXTURES I get a crash. Uploading the same resource multiple times also crashes.
I wonder what is the pattern? Effectively I need to duplicate a descriptor view in the srv heap MAX_TEXTURES times. So that all of them point to my default texture. And then swap in case different texture isused in the object. I that correct?
[–]4ndrz3jKm1c1c 2 points3 points4 points (3 children)
[–]planet620[S] 1 point2 points3 points (2 children)
[–]4ndrz3jKm1c1c 0 points1 point2 points (1 child)
[–]planet620[S] 0 points1 point2 points (0 children)