@@ -29,6 +29,21 @@ namespace pal {
2929
3030Signal::~Signal () {
3131 dev_->context ().svmFree (amdSignal_);
32+
33+ if (ws_ == device::Signal::WaitState::Blocked) {
34+ #if defined(_WIN32)
35+ Pal::Result result = Pal::Result::Success;
36+
37+ Pal::UnregisterEventInfo eventInfo = {};
38+ eventInfo.pEvent = &event_;
39+ eventInfo.trackingType = Pal::EventTrackingType::ShaderInterrupt;
40+ result = dev_->iDev ()->UnregisterEvent (eventInfo);
41+ if (result != Pal::Result::Success) {
42+ ClPrint (amd::LOG_ERROR, amd::LOG_QUEUE,
43+ " Failed to unregister SQ event needed for hostcall buffer" );
44+ }
45+ #endif
46+ }
3247}
3348
3449bool Signal::Init (const amd::Device& dev, uint64_t init, device::Signal::WaitState ws) {
@@ -47,6 +62,47 @@ bool Signal::Init(const amd::Device& dev, uint64_t init, device::Signal::WaitSta
4762 amdSignal_ = new (buffer) amd_signal_t ();
4863 amdSignal_->value = init;
4964
65+ if (ws_ == device::Signal::WaitState::Blocked) {
66+ #if defined(_WIN32)
67+ Pal::Result result = Pal::Result::Success;
68+
69+ Util::EventCreateFlags flags = {};
70+ flags.manualReset = false ;
71+ flags.initiallySignaled = false ;
72+ result = event_.Init (flags);
73+ if (result != Pal::Result::Success) {
74+ ClPrint (amd::LOG_ERROR, amd::LOG_QUEUE,
75+ " Failed to create Pal::Util::Event needed for hostcall buffer" );
76+ return false ;
77+ }
78+
79+ result = event_.Set ();
80+ if (result != Pal::Result::Success) {
81+ ClPrint (amd::LOG_ERROR, amd::LOG_QUEUE,
82+ " Failed to set Pal::Util::Event needed for hostcall buffer" );
83+ return false ;
84+ }
85+
86+ Pal::RegisterEventInfo eventInputInfo = {};
87+ eventInputInfo.pEvent = &event_;
88+ eventInputInfo.trackingType = Pal::EventTrackingType::ShaderInterrupt;
89+ Pal::RegisterEventOutputInfo eventOutputInfo = {};
90+ result = dev_->iDev ()->RegisterEvent (
91+ eventInputInfo,
92+ &eventOutputInfo);
93+ if (result != Pal::Result::Success) {
94+ ClPrint (amd::LOG_ERROR, amd::LOG_QUEUE,
95+ " Failed to register SQ event needed for hostcall buffer" );
96+ return false ;
97+ }
98+ amdSignal_->event_id = eventOutputInfo.shaderInterrupt .eventId ;
99+ amdSignal_->event_mailbox_ptr = eventOutputInfo.shaderInterrupt .eventMailboxGpuVa ;
100+ ClPrint (amd::LOG_INFO, amd::LOG_INIT,
101+ " Registered SQ event %d with mailbox slot %p" ,
102+ amdSignal_->event_id , amdSignal_->event_mailbox_ptr );
103+ #endif
104+ }
105+
50106 return true ;
51107}
52108
@@ -67,7 +123,19 @@ uint64_t Signal::Wait(uint64_t value, device::Signal::Condition c, uint64_t time
67123 } (c);
68124
69125 if (ws_ == device::Signal::WaitState::Blocked) {
70- guarantee (false , " Unimplemented" );
126+ #if defined(_WIN32)
127+ Pal::Result result = Pal::Result::Success;
128+
129+ float timeoutInSec = timeout / (1000 * 1000 );
130+ result = event_.Wait (timeoutInSec);
131+
132+ if (result != Pal::Result::Success) {
133+ return -1 ;
134+ }
135+
136+ std::atomic_thread_fence (std::memory_order_acquire);
137+ return amdSignal_->value ;
138+ #endif
71139 } else if (ws_ == device::Signal::WaitState::Active) {
72140 auto start = amd::Os::timeNanos ();
73141 while (true ) {
0 commit comments